<template>
  <div class="app-container">
    积分等级列表
    <!-- 表格 -->
    <el-table :data="list" border stripe>

      <el-table-column type="index" width="50" />
      <el-table-column prop="borrowAmount" label="借款额度" />
      <el-table-column prop="integralStart" label="积分区间开始" />
      <el-table-column prop="integralEnd" label="积分区间结束" />
      <!-- table组件中添加删除列 -->
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <el-button
            type="danger"
            size="mini"
            icon="el-icon-delete"
            @click="removeById(scope.row.id)"
          >
            删除
          </el-button>
          <!-- 表格“操作”列中增加“修改”按钮 -->
          <router-link :to="'/service/integral-grade/edit/' + scope.row.id" style="margin-right:5px;">
            <el-button type="primary" size="mini" icon="el-icon-edit">
              修改
            </el-button>
          </router-link>
        </template>

      </el-table-column>

    </el-table>

    <!-- 分页 -->
    <el-col :span="20" :xs="24" class="right-align">
      <pagination v-show="total > 0"
                  :total="total" :page.sync="searchObj.pageNum" :limit.sync="searchObj.pageSize"
                  @pagination="fetchData" />
    </el-col>

  </div>
</template>

<script>

import integralGradeApi from '@/api/service/integral-grade'

export default {
  name: 'List',
  // 定义数据模型
  data() {
    return {
      page: 1, // 默认页码
      limit: 10, // 每页记录数
      // 数据列表
      list: [],
      searchObj: {
        pageNum: 1,
        pageSize: 10,
        mobile: null, // 手机号
        userType: null, // 用户类型
        status: null
      } // 查询条件
    }
  },
  // 定义方法
  methods: {
    fetchData() {
      // 调用api
      integralGradeApi.list(this.searchObj).then(response => {
        this.list = response.data.list
        this.total = response.data.total
      })
    },

    // 根据id删除数据
    removeById(id) {
      console.log('adaf:' + id)
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          integralGradeApi.removeById(id).then(response => {
            this.$message.success(response.msg)
            this.fetchData()
          })
        })
        .catch(error => {
          this.$message.info('取消删除')
        })
    }
  },
  created() {
    this.fetchData()
  }
}
</script>

<style scoped>
.right-align {
  text-align: right;
}
</style>
